<?php


namespace app\common\validate;


class MediaValidate extends CommonValidate
{
    protected $rule    = [
        'id|ID'                   => 'require|integer|between:1,100000000',
        'media_group_id|媒体分组ID'   => 'require|integer|between:1,100000000',
        'media_group_name|媒体分组名称' => 'require|length:1,20',
        'product_file_type|商品图类型' => 'require|productFileType',
    ];
    protected $message = [];
    protected $scene   = [
        'postMedia'          => [
            'media_group_id',
        ],
        'putMedia'           => [
            'id',
        ],
        'deleteMedia'        => ['id'],
        'postMediaGroup'     => [
            'media_group_name',
        ],
        'putMediaGroup'      => [
            'media_group_id',
            'media_group_name',
        ],
        'deleteMediaGroup'   => ['media_group_id'],
        'uploadProductImage' => ['productFileType'],
    ];

    protected function productFileType($value): bool
    {
        try {
            if (in_array($value, [
                'logo',
                'share',
                'wechat_share',
                'mini_share',
            ], true)) {
                return true;
            }
            return false;
        } catch (\Exception $e) {
            return false;
        }
    }
}